package com.mall.hadoop.job.tfirstgardenstatistics;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import com.mall.manager.service.AreaMapService;
import com.mall.manager.service.FirstGardenStatisticsService;
/**
 * 第一次登陆统计时间
 * @author liugb
 * @Date 2016 8 1
 */
public class FirstGardenStatisticsReduce extends Reducer<Text, IntWritable, Text, IntWritable>{
	                           
	@Override
	protected void reduce(Text key, Iterable<IntWritable> value,Context context) throws IOException, InterruptedException {
		// TODO Auto-generated method stub		
		try{
			Map<String,Object> map = new HashMap<String,Object>();
			String[] k = key.toString().split("_");
			if(k[0].contains("z")){
				map = AreaMapService.loadAreaMap("p");
			}else if(k[0].contains("x")){
				map = AreaMapService.loadAreaMap("c");
			}else{
				map = AreaMapService.loadAreaMap("a");
			}
			for(IntWritable iw:value){
				FirstGardenStatisticsService.manager_insert_firstgarden(k[0],k[1], iw.get(), map);
			}
		}catch(Exception e){
			e.printStackTrace();
		}	
		
	}
	
}
